﻿using System;
using System.Collections.Generic;
using System.Text;
using Csla.Data;

namespace MinaspetroLibrary.ConvencaoPack
{
     [Serializable()]
    public class ConvencaoChildInfo : Csla.ReadOnlyBase<ConvencaoChildInfo>
    {
        #region Business Properties and Methods

        //declare members

        private Guid _id = Guid.NewGuid();

        private int _idSeq = 0;

        private string _idRegional = string.Empty;

        private string _nome = string.Empty;

        private string _arquivo = string.Empty;

        private string _ano = string.Empty;

        private string _descricao = string.Empty;

        private char _publicar = 'n';

       [System.ComponentModel.DataObjectField(true, true)]
        public Guid Id
        {
            get
            {
                return _id;
            }
        }

        public int IdSeq
        {
            get
            {
                return _idSeq;
            }
        }

        public string IdRegional
        {
            get
            {
                return _idRegional;
            }
        }

        public string Nome
        {
            get
            {
                return _nome;
            }
        }

        public string Arquivo
        {
            get
            {
                return _arquivo;
            }
        }

        public string Ano
        {
            get
            {
                return _ano;
            }
        }

        public string Descricao
        {
            get
            {
                return _descricao;
            }
        }

        public string Publicar
        {
            get
            {
                switch (_publicar)
                {
                    case 's':
                        return "Ativo";
                    case 'n':
                        return "Inativo";
                    default:
                        return "";
                }
            }
        }


        protected override object GetIdValue()
        {
            return _id.ToString();
        }

        #endregion //Business Properties and Methods

        #region Authorization Rules
        protected override void AddAuthorizationRules()
        {
            //TODO: Define authorization rules in ConvencaoChildInfo

        }

        #endregion //Authorization Rules

        #region Factory Methods
        internal static ConvencaoChildInfo GetConvencaoChildInfo(SafeDataReader dr)
        {
            return new ConvencaoChildInfo(dr);
        }

        private ConvencaoChildInfo(SafeDataReader dr)
        {
            Fetch(dr);
        }
        #endregion //Factory Methods

        #region Data Access

        #region Data Access - Fetch
        private void Fetch(SafeDataReader dr)
        {
            FetchObject(dr);

            //load child object(s)
            FetchChildren(dr);

        }

        private void FetchObject(SafeDataReader dr)
        {
            _id = new Guid(dr["Id"].ToString().Trim().Replace("\"", "\\\""));
            _idSeq = dr.GetInt32("IdSeq");
            _idRegional = dr.GetString("IdRegional");
            _nome = dr.GetString("Nome");
            _arquivo = dr.GetString("Arquivo");
            _ano = dr.GetString("Ano");
            _descricao = dr.GetString("Descricao");
            _publicar = dr.GetChar("Publicar");
       
        }

        private void FetchChildren(SafeDataReader dr)
        {
        }
        #endregion //Data Access - Fetch
        #endregion //Data Access
    }
}
